package drukarnia.controller;

import java.io.IOException;
import java.net.MalformedURLException;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.lowagie.text.BadElementException;

public class ImageManager {
	
	public Double getSizeInM2(float X, float Y, int DpiX, int DpiY){
		DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
		symbols.setDecimalSeparator('.');
		DecimalFormat df = new DecimalFormat("#.####", symbols);
		
		
		double sizeInInchX = X/DpiX;
		double sizeInInchY = Y/DpiY;
		System.out.println("Sajzy: " + sizeInInchX + ", " + sizeInInchY );
		sizeInInchX = Double.valueOf(df.format(sizeInInchX));
		sizeInInchY = Double.valueOf(df.format(sizeInInchY));
		
		double sizeInM_X = sizeInInchX * 0.0254;
		sizeInM_X = Double.valueOf(df.format(sizeInM_X));
		double sizeInM_Y = sizeInInchY * 0.0254;
		sizeInM_Y = Double.valueOf(df.format(sizeInM_Y));
		System.out.println("Rozmiar w m: " + sizeInM_X + "m, " + sizeInM_Y + "m");
		
		double sizeInM2 = sizeInM_X * sizeInM_Y;
		sizeInM2 = Double.valueOf(df.format(sizeInM2));
		System.out.println("Size: " + sizeInM2 + "m2");
		
		return sizeInM2;
	}
	
//	public static void main(String[] args) throws BadElementException, MalformedURLException, IOException {
//		ImageManager imga = new ImageManager();
//		com.lowagie.text.Image img = com.lowagie.text.Image.getInstance("C:\\Users\\Jacek\\Desktop\\plakat4-white.tif");
//		double sizeInM2 = imga.getSizeInM2(img.getWidth(), img.getHeight(), img.getDpiX(), img.getDpiY());
//		System.out.println("Size2: " + sizeInM2 + "m2");
//	}

}
